package com.ydl.partitionscheduler.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class PartitionStrategyFactory {

    private final Map<String, PartitionStrategy> strategies = new HashMap<>();

    @Autowired
    public PartitionStrategyFactory(List<PartitionStrategy> strategyList) {
        for (PartitionStrategy strategy : strategyList) {
            strategies.put(strategy.getStrategyName(), strategy);
        }
    }

    public PartitionStrategy getStrategy(String strategyName) {
        PartitionStrategy strategy = strategies.get(strategyName);
        if (strategy == null) {
            throw new IllegalArgumentException("不支持的分区策略: " + strategyName);
        }
        return strategy;
    }
}
